<?php 
/**
* @author Oliver Leisalu, Inditel Meedia
* @package DomFg
* @subpackage Input
*/
class DomFgButton extends DomFgInput {
	
	protected $confirmMessage;
	
	protected $link;

	protected $submitLink;
	
	protected $value = 1;
	
	protected $target = '_self';
	
	public function __construct( $name = NULL, $title = NULL ) {
		parent::__construct( $name );
		$this->title( $title );
	}
	
	public function name( $name ) {
		parent::name( $name );
		return $this;
	}
	
	public function title( $title ) {
		$this->title = $title;
		return $this;
	}
	
	public function confirmMessage( $confirmMessage ) {
		$this->confirmMessage = $confirmMessage;
		return $this;
	}
	
	public function value( $value ) {
		$this->value = htmlspecialchars($value);
	}
	
	public function link( $link ) {
		$this->link = $link;
		return $this;
	}
	
	public function target( $target ) {
		$this->target = $target;
	}
	/**
	 * Submits form to this link
	 *
	 * @param String $link
	 */
	public function submitLink( $link ) {
		$this->submitLink = $link;
	}
	
	public static function parsePost( $name, &$value ) {
		if( $value == 0 or $value == 1 ) 
			return (bool)$value;
		else
			return $value;
	}
	
	public function render() {

		$this->onClick('fg_button_click(this, \''.$this->name.'\', \''.$this->value.'\',\''.$this->link.'\',\''.$this->submitLink.'\', \''.$this->target.'\',\''.$this->confirmMessage.'\');');
		$renderer = $this->getRenderer();
		$renderer->assign('input', $this );
		return $renderer->fetch('Input/Button.html');
	}
	

}
?>